﻿<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>登录</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="renderer" content="webkit">
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="stylesheet" href="/static/admin/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/admin/css/login.css">
</head>
<body>
<div class="container">
    <div class="login-wrapper">
        <div class="login-screen">
            <div class="well">
                <div class="login-form">
                    <img id="profile-img" class="profile-img-card" src="<?php if ($portrait) echo $portrait; else echo '/static/admin/picture/avatar.png'; ?>" />
                    <p id="profile-name" class="profile-name-card"></p>
                    <form action="<?php echo url('login/login')?>" method="post" id="login-form">
                        <div id="errtips" class="hide"></div>
                        <div class="input-group">
                            <div class="input-group-addon"><span class="glyphicon glyphicon-user" aria-hidden="true"></span></div>
                            <input type="text" class="form-control" id="username" placeholder="用户名" name="username" autocomplete="off" data-rule="用户名:required;username" />
                        </div>
                        <div class="input-group">
                            <div class="input-group-addon"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span></div>
                            <input type="password" class="form-control" id="password" placeholder="密码" name="password" autocomplete="off" data-rule="密码:required;password" />
                        </div>
                        <div class="input-group">
                            <input type="text" class="form-captcha" id="captcha" placeholder="验证码" name="captcha"/>
                            <img class="captcha-img" src="{:captcha_src()}" onclick="javascript:this.src='{:captcha_src()}?rand='+Math.random()" alt="captcha" /> <span class="captcha-img-txt">点击图片切换</span>
                        </div>
                        <div class="input-group">
                            <label class="inline" for="remember"><input type="checkbox" name="remember" id="remember" value="1" /><span class="remember">保持会话</span></label>
                        </div>
                        <div class="form-group">
                            <button type="button" id="login" class="btn btn-success btn-lg btn-block">登 录</button>
                        </div>
                    </form>
                </div>
            </div>
            <p class="copyright"><a href="www.itspire.cn">Powered By MyAdmin</a></p>
        </div>
    </div>
</div>
<script type="text/javascript" src="/lib/jquery.min.js"></script>
<script type="text/javascript" src="/lib/layer/3.1.1/layer.js"></script>
<script type="text/javascript" src="/lib/jQuery.Form.js"></script>
<script type="text/javascript">
$(function(){
    if (window !== top) {
        top.location.href = location.href;
    }
    const JUMP_URL  = "<?php echo url('index/index')?>";

    $('#login').click(function () {
        const options = {
            dataType: "json",   //html(默认), xml, script, json...接受服务端返回的类型
            //clearForm: true,   //成功提交后，是否清除所有表单元素的值
            //resetForm: true,   //成功提交后，是否重置所有表单元素的值
            timeout: 3000,      //限制请求的时间，当请求大于3秒后，跳出请求
            beforeSubmit: function () {
                const username = $('#username').val();
                const password = $('#password').val();
                const captcha  = $('#captcha').val();
                if(username === ''){
                    layer.msg('请填写用户名',{icon:5,time:2000});
                    return false;
                }
                if(password === ''){
                    layer.msg('请填写密码',{icon:5,time:2000});
                    return false;
                }
                if(captcha === ''){
                    layer.msg('请填写验证码',{icon:5,time:2000});
                    return false;
                }
                load = layer.load();
            },
            success: function(obj){
                if(obj.code !== 0){
                    layer.msg(obj.msg,{ icon:5, time:2000 });
                } else {
                    layer.msg('登录成功', { icon: 1, time: 2000 }, function(){
                        location.href = JUMP_URL;
                    });
                }
                layer.close(load);
            },
            error:function (obj, status, msg) {
                console.log(obj, status, msg);
                layer.msg(msg,{ icon:5, time:3000 }, function () {
                    layer.close(load);
                });
            }
        };
        $('#login-form').ajaxSubmit(options);
    });
});
</script>
</body>
</html>